package net.zjitc.controller;

/**
 * @Author admin
 * @Date 2019/3/25 9:02
 */

import net.zjitc.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;

/**
 *  将用户模块的所有处理方法都在此类中*/
@Controller
public class UserController {
    @RequestMapping(value = "/user/findAll")
    //用户查询
    public ModelAndView findAll(){
        ModelAndView modelAndView = new ModelAndView();
        List<User> list = new ArrayList<>();
        User user = new User(1);
        user.setId(1);
        user.setUsername("张三");
        user.setPassword("123456");
        list.add(user);
        modelAndView.addObject("list",list);
        modelAndView.setViewName("/test.jsp");
        return modelAndView;
    }

    //通过id查找
    @RequestMapping("/findById")
    public ModelAndView findById(int id) {
        ModelAndView modelAndView = new ModelAndView();
        List<User> list = new ArrayList<>();
        User user = new User(1);
        user.setId(1);
        user.setUsername("李四");
        user.setPassword("123456");
        modelAndView.addObject("user",user);
        modelAndView.setViewName("/user.jsp");
        return modelAndView;
    }


    @RequestMapping("/getUserAddress")
    public String getUserAddress(User user){
        System.out.println(user);
        return null;
    }


    @RequestMapping("/testHeader")
    public String testHeader(@RequestHeader("User-Agent") String str,
                             @CookieValue("JSESSIONID")String sessionoId){
        System.out.println(str);
        System.out.println(sessionoId);
        return null;

    }

    @PatchMapping("/testCheckbox")
    public String testCheckbox(int [] ids){
        System.out.println(ids);
        return null;

    }

    @RequestMapping("/register")
    public String register(User user){
        System.out.println(user);
        return "user/login";

    }

    @PatchMapping("/findAllProduct")
    public String findAllProduct(){
        return "product/list";
    }




}
